<template>
  <div class='mePage'>
    <div class="page-loadmore-wrapper" ref="wrapper">
      <mt-loadmore
        :auto-fill=false
        @translate-change="translateChange"
        :bottom-method="loadBottom"
        @bottom-status-change="handleBottomChange"
        ref="loadmore">
        <div class="headerBox" @click='_handleGoSet' v-if="otherUser">
          <div class="headerLeft">
            <div class="headerLeftTop">
              <div class="nickName">{{otherUser.nickname}}</div>
              <div class="address">{{otherUser.birthday}}</div>
            </div>
            <div class="headerLeftBottom">
              <div class="catch">
                <div class="catchTop">{{otherUser.catch_num}}</div>
                <div>Catch</div>
              </div>
              <div class="catch">
                <div class="catchTop">{{otherUser.caught_num}}</div>
                <div>Caught</div>
              </div>
            </div>
          </div>
          <div class="headerRight" :style="{backgroundImage:`url(${otherUser.avatar})`}"></div>
        </div>
        <div v-if="raindropList.length > 0" class="raindropBox">
          <div class="raindropHead" @click='_handleGoAdd'>
            <div class="allRaindrop">Raindrops</div>
            <div class="seeAll">{{raindropList.length}}</div>
          </div>
          <div class="raindropWrap">
            <rain-drop
              v-for="(item,index) in raindropList"
              :key=index
              :raindropItem='item'
            />
          </div>
        </div>
        <no-content
          imgIcon='meNoIcon'
          content='No Raindrop Yet'
          v-if="raindropList.length === 0"
        >
          <div
            @click="_handleAddRaindrop"
            v-if="!isUid"
            class="addRain"
            slot='add'>Add Raindrop
          </div>
        </no-content>
      </mt-loadmore>
    </div>

  </div>

</template>

<script>
  import RainDrop from './RainDrop'
  import NoContent from '../../components/common/NoContent'

  import api from '../../plugins/api'
  import { Toast } from 'mint-ui'

  const Cookie = process.browser ? require('js-cookie') : undefined

  export default {
    components: { RainDrop, NoContent },
    asyncData() {
      return {}
    },
    data() {
      return {
        uid: this.$route.params.uid,
        otherUser: null,
        raindropList: [],
        topStatus: '',
        bottomStatus: '',
        wrapperHeight: 0,
        translate: 0,
        page: 1
      }
    },
    props: {
      // otherUser: {
      //   type: Object,
      //   default() {
      //     return {}
      //   }
      // }
    },
    computed: {
      isUid() {
        return this.$route.params.uid
      }
    },
    created() {
      this._renderUserInfo()
      this._renderRaindrop()
    },
    methods: {
      //去设置页面
      _handleGoSet() {
        this.$router.push({path:'/me/setting'})
      },
      //去添加raindrop
      _handleGoAdd () {
        this.$router.push({path:'/me/add'})
      },
      //获取用户信息
      async _renderUserInfo() {
        const params = {
          sid: Cookie.get('sid'),
          uid: this.uid || Cookie.get('user')
        }
        let res = await api.getOtherUser(params)
        if (res.status == 0) {
          this.otherUser = res.data

          Cookie.set('userInfo',{
            avatar:res.data.avatar,
            name:res.data.nickname,
            birthday:res.data.birthday,
            gender:res.data.gender
          })

        } else {
          Toast(res.info)
        }
      },

      //获取用户raindrop
      async _renderRaindrop() {
        const params = {
          sid: Cookie.get('sid'),
          uid: this.uid || Cookie.get('user')
        }
        let res = await api.getUserTag(params)
        if (res.status == 0) {
          this.raindropList = res.data
          // console.log(this.raindropList)
        } else {
          Toast(res.info)
        }
      },

      //上拉状态
      handleBottomChange(status) {
        this.bottomStatus = status
      },

      //上拉加载
      loadBottom() {
        this.$refs.loadmore.onBottomLoaded()

      },
      translateChange(translate) {
        // console.log(translate)
      },
      _handleAddRaindrop() {
        console.log('add')
      }
    }
  }
</script>
<style lang="scss">

  .mePage {
    height: 100% !important;
    width: 100% !important;
    font-size: 28px;
    color: #7F7F7F;

    /*div {*/
    /*height: fit-content;*/
    /*width: auto;*/
    /*}*/

    .page-loadmore-wrapper {
      height: 100%;
      overflow: scroll;
      flex-grow: 1;
    }

    .mint-loadmore-bottom span {
      display: inline-block;
      -webkit-transition: .2s linear;
      transition: .2s linear;
      vertical-align: middle
    }

    .mint-loadmore-bottom span.is-rotate {
      -webkit-transform: rotate(180deg);
      transform: rotate(180deg)

    }

    .headerBox {
      width: 100%;
      padding: 22px 52px 80px 40px;
      border-bottom: 1px solid rgba(0, 0, 0, .1);
      display: flex;
      justify-content: space-between;

      .headerLeft {
        .nickName {
          max-width: 400px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          color: #4C4C4C;
          font-size: 48px;
          font-weight: bold;
          line-height: 56px;
          position: relative;

          &:before {
            content: '';
            position: absolute;
            width: 12px;
            height: 20px;
            right: -30px;
            top: 56%;
            margin-top: -10px;
            background: url("../../assets/images/8.png") no-repeat center;
            -webkit-background-size: cover;
            background-size: cover;
          }
        }

        .address {
          line-height: 38px;
        }

        .headerLeftBottom {
          display: flex;
          padding-top: 50px;

          .catch {
            min-width: 68px;
            margin-right: 40px;

            .catchTop {
              color: #4C4C4C;
              font-size: 36px;
              font-weight: bold;
              line-height: 46px;
            }
          }
        }
      }

      .headerRight {
        width: 176px;
        height: 176px;
        border-radius: 50%;
        background: url("") no-repeat center;
        -webkit-background-size: cover;
        background-size: cover;
      }
    }

    .raindropBox {
      width: 100%;
      padding: 0 22px;

      .raindropHead {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 94px;
        width: 100%;

        .allRaindrop {
          font-size: 34px;
          padding-left: 18px;
        }

        .seeAll {
          padding-right: 40px;
          color: #BFBFBF;
          font-size: 26px;
          font-weight: bold;
          position: relative;

          &:after {
            content: '';
            position: absolute;
            width: 32px;
            height: 32px;
            right: 2px;
            top: -2px;
            background: url("../../assets/images/16.png") no-repeat center;
            -webkit-background-size: cover;
            background-size: cover;
          }
        }
      }
    }

    .raindropWrap {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
    }
  }

</style>
